def read_file():
    
    a = 10
    b = 0
    
    try:
        rst = a / b
        print(rst)
        
        print("计算正常")
        return rst
    except ZeroDivisionError as e:
        print("除数不能为0")    
    
    finally:
        print("关闭文件资源")

def write_file():
     
    a = 10
    b = 2
    rst = a / b
    f = open("haha.txt","w")
    
    try:
        f.write("rst: {}".format(rst))
    except Exception as e:
        print("出现异常",e,type(e))
    finally:
        f.close()
        print("关闭资源")    
    
               
        
        
if __name__ == '__main__':
    #read_file()
    write_file()    